package com.example.shuiyin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.shuiyin.entity.AvatarHistory;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AvatarHistoryMapper extends BaseMapper<AvatarHistory> {
    
    /**
     * 获取用户的所有头像历史记录，按创建时间倒序排列
     */
    @Select("SELECT * FROM avatar_history WHERE user_id = #{userId} ORDER BY created_at DESC")
    List<AvatarHistory> selectByUserId(@Param("userId") Long userId);
    
    /**
     * 将用户所有头像标记为非活动状态
     */
    @Update("UPDATE avatar_history SET is_active = false WHERE user_id = #{userId}")
    void deactivateAllAvatars(@Param("userId") Long userId);
} 